
eststo clear
set more off
use Data/event_study_sample_quartsince2006.dta, clear  // postcode data

*3940 Capel Sound not in house price data - use rosebud 3939
 	rename postcode postcode_orig
	
	
	gen postcode = postcode_orig
	
	replace postcode = 3939 if postcode_orig==3940
 
 merge m:1 postcode contract_quarter using Data/postcodequarter_house_unit_prices.dta // missing 2016
 drop _merge
 	
	

merge m:1 postcode using Data/AboveBelowRoof.dta, keepusing(above_med* quintiles_Re NCustomer_pc) // created in Desc_stats_roof

drop _merge 

 

		
		
		drop year
		
		gen year = yofd(dofq(contract_quarter))
		
rename postcode postcode_new

rename postcode_orig postcode 
 
 
		
		replace postcode = postcode_new if postcode==. // pre 2006 data 	

	by postcode, sort: egen minTotalhouse = min(TotalH_)
	replace TotalH_ = minTotalhouse if TotalH_ ==.
	

			
		reg houseprice  i.above_medRelative##i.year   [aweight =TotalH_]  if housesales >= 10 & housesales< 200  ,  cluster(postcode)

		
margins year, dydx(above_medRelative)

est store cum
marginsplot,  recastci(rarea) ciopts(color(gs14)) plotopts(color(gs5)   msize(small)) ///
 xtitle("Year") ytitle("Difference in House Price") title("") xlabel(2000(2)2014)

	graph export Analysis/houseprices_yearweightroofrelative.png, as(png) replace
	

	
	
	
	
	

use Data/event_study_samplewithsolar.dta, clear

	merge m:1 account_id contract_start_month using Data/accounts_panel.dta, keepusing(concession_type payment)

	drop concession


	encode concession_type, gen(concession)

	by account_id, sort: egen min_concession = min(concession)

	replace concession = min_concession if concession ==.

	gen not_concession = concession==.

	

	encode payment, gen(autodebit)

	by account_id, sort: egen min_debit = min(autodebit)

	replace autodebit = min_debit if autodebit==.
	
	gen not_directdebit = autodebit==1 | autodebit==2

	
	
	collapse (mean) not_directdebit not_concession (firstnm) postcode has_solar ever_solar year,  by(account_id contract_quarter)
	
	save Data/account_paymentconcessions_quarterly_withsolar, replace
	
	drop if has_solar ==1 | ever_solar ==1
	
	
	use Data/account_paymentconcessions_quarterly_withsolar, clear
	
	collapse (mean) not_directdebit not_concession	year ,  by(postcode contract_quarter)
	
	save Data/postcodequarter_paymentconcession.dta, replace
	
	
	
	
	
	
	
	merge m:1 postcode using Data/AboveBelowRoof.dta, keepusing(above_med* quintiles_Re NCustomer_pc)
	

		label var contract_quarter "Year-Quarter"


** difference in direct debit  by dwelling suitablity 
reg not_directdebit i.above_medRelative#i.contract_quarter   [aweight =NCustomer_pc] if year!=2016 & contract_quarter< tq(2008q1), cluster(postcode) 


margins contract_quarter, dydx(above_medRelative)

est store green_diff

marginsplot,  recastci(rarea) ciopts(color(gs14)) plotopts(color(gs5)   msize(small)) ytitle("Difference in direct debit (% customers)" , size(Large)) title("") yscale(range(-0.2 0.2)) ylabel(-0.2(0.1)0.2)


graph export Analysis/diff_direct20062007_quarter.png, as(png) replace







reg not_directdebit i.above_medRelative#i.contract_quarter   [aweight =NCustomer_pc] if year!=2016 , cluster(postcode) 


margins contract_quarter, dydx(above_medRelative)

est store green_diff

marginsplot,  recastci(rarea) ciopts(color(gs14)) plotopts(color(gs5)   msize(small)) ytitle("Difference in direct debit (% customers)" , size(Large)) title("") yscale(range(-0.2 0.2)) ylabel(-0.2(0.1)0.2)


graph export Analysis/diff_direct20062015_quarter.png, as(png) replace









** difference in concession by dwelling suitablity 
reg not_concession i.above_medRelative#i.contract_quarter  [aweight =NCustomer_pc] if year!=2016 & contract_quarter< tq(2008q1), cluster(postcode) 


margins i.contract_quarter, dydx(above_medRelative)

est store green_diff

marginsplot,  recastci(rarea) ciopts(color(gs14)) plotopts(color(gs5)   msize(small)) ytitle("Difference in concession status (% customers)" , size(Large)) title("") yscale(range(-0.2 0.2)) ylabel(-0.2(0.1)0.2)


graph export Analysis/diff_concession20062007_quarter.png, as(png) replace

		
		
		
		
		
** difference in concession by dwelling suitablity 
reg not_concession i.above_medRelative#i.contract_quarter  [aweight =NCustomer_pc] if year!=2016, cluster(postcode) 


margins i.contract_quarter, dydx(above_medRelative)

est store green_diff

marginsplot,  recastci(rarea) ciopts(color(gs14)) plotopts(color(gs5)   msize(small)) ytitle("Difference in concession status (% customers)" , size(Large)) title("") yscale(range(-0.2 0.2)) ylabel(-0.2(0.1)0.2)


graph export Analysis/diff_concession20062015_quarter.png, as(png) replace

		
		
		
		
		
		
		
		
		
